package greed;

public class maxProfit {
    public int maxProfit(int[] prices) {
        // 第一想法是逆向双指针
        int profit = 0,low=10000;
        for(int i=0;i<prices.length;i++){
            if (prices[i]<low) {
                low=prices[i];
            }else if(prices[i]-low>profit){
                profit=prices[i]-low;
            }
        }
        return profit;
    }

    public static void main(String[] args) {
        maxProfit obj = new maxProfit();
        // int[] prices =new int[]{7,1,5,3,6,4};
        // int[] prices =new int[]{7,6,4,3,1};
        // int[] prices =new int[]{3,3,4,1,2,20,1,10};
        // int[] prices =new int[]{2,3,4,1,2,20,4,6,10};
        // int[] prices =new int[]{5,7,2,7,3,3,5,3,0};
        int[] prices =new int[]{0,3,8,6,8,6,6,8,2,0,2,7};
        System.out.println(obj.maxProfit(prices));
    }
}
